package com.mlz.mlzmall.ui.activity.act.personal;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mlz.mlzmall.R;
import com.mlz.mlzmall.ui.activity.act.base.TopTitleView;
import com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.VolleyBaseActivity;
import com.mlz.mlzmall.ui.dialog.SettingDialog;
import com.mlz.mlzmall.ui.utils.util.FileUtil;

/**
 * describe :
 * PackageName com.mlz.mall.ui.activity.act.personal.
 * ProjectName mlzMall_v2.0.
 */
public class SettingActivity extends VolleyBaseActivity {

    private RelativeLayout rl_to_clean_cache;//清理缓存
    private RelativeLayout rl_about_mlz;//关于美篮子
    private TextView tv_cache;//缓存

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);//设置界面
        setViewContent();
        initView();
    }
    private void setViewContent() {
        TopTitleView loginTopTitle = (TopTitleView) findViewById(R.id.login_top_title);
        loginTopTitle.setLeftButtonContent(null, R.mipmap.pic_2_1_btn_back, null);
        loginTopTitle.setTitleButtonContent("设置", null, null);
        loginTopTitle.setOnLeftButtonClickListener(new TopTitleView.OnLeftButtonClickListener() {
            @Override
            public void onLeftBtnClick(View button) {
                finish();
                SettingActivity.this.overridePendingTransition(R.anim.right_in,R.anim.right_out);
            }
        });
    }
    private void initView() {
        rl_to_clean_cache = (RelativeLayout) findViewById(R.id.rl_to_clean_cache);
        rl_about_mlz = (RelativeLayout) findViewById(R.id.rl_about_mlz);
        tv_cache = (TextView) findViewById(R.id.tv_cache);
        try { // 所有图片，文件， 视频
            tv_cache.setText(FileUtil.getFormatSize(FileUtil.getAllImgCacheSize(SettingActivity.this)
                    + FileUtil.getFolderSize(SettingActivity.this.getFilesDir()) + FileUtil.getAllVideoCacheSize()));

        } catch (Exception e) {
            e.printStackTrace();
        }
        rl_to_clean_cache.setOnClickListener(this);
        rl_about_mlz.setOnClickListener(this);
    }

    Intent intent;
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_to_clean_cache:
                SettingActivity.this.overridePendingTransition(R.anim.left_in, R.anim.left_out);
                dialog();//弹出提示是否删除窗
                break;
            case R.id.rl_about_mlz:
                intent = new Intent(SettingActivity.this, AboutMlzActivity.class);
                startActivity(intent);
                SettingActivity.this.overridePendingTransition(R.anim.left_in, R.anim.left_out);
                break;
        }
    }

    private void dialog() {
        SettingDialog.clear(SettingActivity.this);
        SettingDialog.tv_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               clear();
                SettingDialog.pWindow.dismiss();
            }
        });
    }

    private void clear() {
        try {
            FileUtil.cleanInternalCache(SettingActivity.this);
            FileUtil.cleanDatabases(SettingActivity.this);
            FileUtil.cleanSharedPreference(SettingActivity.this);
            FileUtil.cleanFiles(SettingActivity.this);
            FileUtil.cleanExternalCache(SettingActivity.this);
            FileUtil.cleanApplicationData(SettingActivity.this);
            FileUtil.clearAllPicCoach(SettingActivity.this);
            tv_cache.setText(FileUtil.getFormatSize(FileUtil.getAllImgCacheSize(SettingActivity.this) +
                    FileUtil.getFolderSize(SettingActivity.this.getFilesDir()) + FileUtil.getAllVideoCacheSize()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
